package com.blue.http.message;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import io.netty.handler.codec.http.multipart.FileUpload;

/**
 * 上传文件对象的默认实现
 * 
 * @author zhengj
 * @since 1.0 2017年3月27日
 */
public class DefaultUploadFile implements UploadFile
{
	private int size;
	private File file;
	private String contentType;
	private String originalName;
	
	public DefaultUploadFile(FileUpload fileUpload) throws IOException
	{
		file = fileUpload.getFile();
		size = (int)file.length();
		contentType = fileUpload.getContentType();
		originalName = fileUpload.getFilename();
	}

	@Override
	public int getSize()
	{
		return size;
	}

	@Override
	public String getContentType()
	{
		return contentType;
	}

	@Override
	public String getOriginalName()
	{
		return originalName;
	}

	@Override
	public File getFile()
	{
		return file;
	}

	@Override
	public InputStream getInputStream() throws IOException
	{
		return new FileInputStream(file);
	}

	@Override
	public String toString()
	{
		return String.format("%s [%s] - %s [%d byte]", originalName, contentType, file, size);
	}
	
	
}
